﻿#region 命名空间
using DW.SharpTools;
#endregion

namespace ContentFactory
{
    /// <summary>
    /// 素材目录。
    /// </summary>
    public sealed class ContentDirectory : ContentObject
    {
        #region 属性

        /// <summary>
        /// 素材目录下的对象集合。
        /// </summary>
        public EnhancedObservableCollection<ContentObject> Children
        {
            get { return _children; }
            set { _children = value; }
        }
        EnhancedObservableCollection<ContentObject> _children;

        #endregion

        #region 初始化

        /// <summary>
        /// 初始化。
        /// </summary>
        public ContentDirectory()
        {
            _children = new EnhancedObservableCollection<ContentObject>();
            Icon = IconManager.GetDirectoryIcon();
        }

        #endregion

        #region 方法

        /// <summary>
        /// 添加子级素材目录。
        /// </summary>
        public void AddDirectory(ContentDirectory childDirectory)
        {
            int index = 0;
            for (int i = 0; i < _children.Count; i++)
            {
                if (_children[i] is ContentBuilder)
                {
                    index = i;
                    break;
                }
            }
            _children.Insert(index, childDirectory);
            childDirectory.Project = Project;
            childDirectory.Parent = this;
            Project.OnDirectoryAdded(childDirectory);
        }

        /// <summary>
        /// 添加子级素材。
        /// </summary>
        public void AddContent(ContentBuilder childContent)
        {
            _children.Add(childContent);
            childContent.Project = Project;
            childContent.Parent = this;
            Project.OnContentAdded(childContent);
        }

        /// <summary>
        /// 删除子级素材目录。
        /// </summary>
        public void RemoveDirectory(ContentDirectory childDirectory)
        {
            _children.Remove(childDirectory);
            childDirectory.Project = null;
            childDirectory.Parent = null;
            Project.OnDirectoryRemoved(childDirectory);
        }

        /// <summary>
        /// 删除子级素材。
        /// </summary>
        public void RemoveContent(ContentBuilder childContent)
        {
            _children.Remove(childContent);
            childContent.Project = null;
            childContent.Parent = null;
            Project.OnContentRemoved(childContent);
        }

        #endregion
    }
}
